//-------------------------------------------------------------------------------------------
//js工具类
//-------------------------------------------------------------------------------------------
var utils = new Object();

//-------------------------------------------------------------------------------------------
//获取到当前项目的名称
//-------------------------------------------------------------------------------------------
utils.contextPath = function() {
    return  "/" + location.pathname.split("/")[1];
}
//-------------------------------------------------------------------------------------------
//将一个对象转化为json字符串
//-------------------------------------------------------------------------------------------
utils.toJSON = function(jsonObject){
	return JSON.stringify(jsonObject);
}
//-------------------------------------------------------------------------------------------
//将一个json字符串转化为对象
//-------------------------------------------------------------------------------------------
utils.praseJSON =function(jsonStr){
	return $.parseJSON(jsonStr);  
}
//-------------------------------------------------------------------------------------------
//判断参数是否是数组
//-------------------------------------------------------------------------------------------
utils.isArray = function(param){
	//判断这个参数是数组还是对象
	if (typeof param === 'object' && !isNaN(param.length)) { 
		return true;
	}else{
		return false;
	}
}

//-------------------------------------------------------------------------------------------
//生成UUID
//-------------------------------------------------------------------------------------------
utils.uuid = function(){
	//获取系统当前的时间
	var d = new Date().getTime();
	//替换uuid里面的x和y
	var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
	  //取余 16进制
	  var r = (d + Math.random()*16)%16 | 0;
	  //向下去整
	  d = Math.floor(d/16);
	  //toString 表示编程16进制的数据
	  return (c=='x' ? r : (r&0x3|0x8)).toString(16);
	});
	return uuid;
};
//-------------------------------------------------------------------------------------------
//创建等影藏的input 的dom
//id  dom的id
//val input设定的值
//-------------------------------------------------------------------------------------------
utils.createInputDom = function(id,valStr){
	//之前节点的id
	var preNodeId = $("#"+id).val();
	if(preNodeId == undefined){
		//添加id
		$("body").append('<input type="hidden" id="'+id+'" value="'+valStr+'"/>');
	}else{
		//存在的情况下，更新id即可
		$("#"+id).val(valStr);
	}
}


